package com.itheima.mm.wx.service.impl;

import com.itheima.mm.pojo.Course;
import com.itheima.mm.pojo.Dict;
import com.itheima.mm.vo.CourseVO;
import com.itheima.mm.wx.mapper.CourseMapper;
import com.itheima.mm.wx.mapper.DictMapper;
import com.itheima.mm.wx.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description DictMapper
 * @Author junyi
 * @Date 2024-06-27
 */
@Service
public class CommonServiceImpl implements CommonService {

    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private DictMapper dictMapper;

    /**
     * 获取城市列表
     *junyi
     * @param tag
     * @return
     */
    @Override
    public List<Dict> getCityList(String tag) {
        List<Dict> dictList = dictMapper.selectCityList(tag);
        return dictList;
    }

    /**
     * 根据地理信息，获取某一具体城市
     *junyi
     * @param cityName
     * @return
     */
    @Override
    public Dict getCityName(String cityName) {
        return  dictMapper.selectCityName(cityName);
    }


    /**
     * kangwei
     * 获取课程列表
     */
    //获取学科列表
    @Override
    public List<CourseVO> getCourseList() {
        //获取属性值
        List<Course> courseList = courseMapper.getCourseList();

        List<CourseVO> courseVOList = courseList.stream().map(course -> {
            CourseVO courseVO = new CourseVO();
            //使用CourseVO来接收属性值
            courseVO.setTitle(course.getName());
            courseVO.setId(course.getId());
            courseVO.setIcon(course.getIcon());
            //若为空，则使用默认图片填充
            if(course.getIcon().equals("") || course.getIcon()==null){
                courseVO.setIcon("empty");
            }


            return courseVO;
        }).collect(Collectors.toList());
        return courseVOList;
    }

}
